<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>My first three.js app</title>
    <style>
        body {
            margin: 0;
        }
    </style>
    <script type="importmap">
        {
            "imports": {
                "three": "./build/three.module.js",
                "three/addons/": "./examples/jsm/"
            }
        }
  </script>
</head>

<body>
    <script type="module">
        import * as THREE from 'three';
        import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
        import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
        import Stats from 'three/addons/libs/stats.module.js';
        import { Rhino3dmLoader } from 'three/addons/loaders/3DMLoader.js';

        const width = window.innerWidth;
        const height = window.innerHeight;

        // 创建场景 相机 渲染器 
        const scene = new THREE.Scene()
        const camera = new THREE.PerspectiveCamera(30, width / height, 1, 3000);
        const renderer = new THREE.WebGLRenderer()
        renderer.setSize(width, height)
        camera.position.set(10, 10, 10);
        camera.lookAt(0, 0, 0);

        // 添加辅助坐标轴
        const axesHelper = new THREE.AxesHelper(150);
        scene.add(axesHelper)

        let loader = new GLTFLoader();
        loader.load(
            // resource URL
            './rehongxi.gltf',
            // called when the resource is loaded
            function (gltf) {
                scene.add(gltf.scene);
                gltf.scene.scale.set(15, 15, 15)
                gltf.scene.rotateX(80.1)
                gltf.scene.position.set(.5, 0, 0)

                renderer.render(scene, camera)
            },

            function (xhr) {
                console.log((xhr.loaded / xhr.total * 100) + '% loaded');

            },
            function (error) {
                console.log('An error happened');
            }
        );

        // 创建几何体
        // const geometry = new THREE.SphereGeometry(50);  // 球体
        // const geometry = new THREE.CylinderGeometry(50, 50, 100); // 圆柱体
        // const geometry = new THREE.PlaneGeometry(100, 50); // 矩形平面
        // const geometry = new THREE.CircleGeometry(50); // 圆型平面
        // const material = new THREE.MeshLambertMaterial({
        //     color: 0x00ffff,
        //     transparent: true,
        //     opacity: 0.5
        // })
        // const mesh = new THREE.Mesh(geometry, material)
        // mesh.position.set(0, 0, 0);

        // var pointLight = new THREE.PointLight(0x26E250, 1) // 创建点光源
        // scene.add(pointLight) // 将点光源添加到场景

        // 平行光
        const directionalLight = new THREE.DirectionalLight("0x26E250", 1);
        directionalLight.position.set(50, 50, 50);
        // directionalLight.target = mesh;
        scene.add(directionalLight);

        const directionalLight2 = new THREE.DirectionalLight("0x26E250", 1);
        directionalLight2.position.set(-50, -50, -50);
        scene.add(directionalLight2);

        // 环境光
        // const ambient = new THREE.AmbientLight("0x26E250", .7);
        // scene.add(ambient);

        // 辅助光源
        // const dirLightHelper = new THREE.DirectionalLightHelper(directionalLight, 10);
        // scene.add(dirLightHelper);


        // 轨道控制器
        const controls = new OrbitControls(camera, renderer.domElement);
        controls.addEventListener('change', function () {
            renderer.render(scene, camera); //执行渲染操作
        });//监听鼠标、键盘事件

        renderer.setClearColor('rgb(135,206,250)', 1.0);

        // 添加
        // scene.add(mesh)
        document.body.appendChild(renderer.domElement);

        renderer.render(scene, camera)

    </script>
    <!-- <script type="importmap" src="./main.js"></script> -->
</body>

</html>